<?php
class ControllerModuleImageRow extends Controller {
	public function index($setting) {
		$data['images'] = array();

		if (isset($setting['image']) && $setting['image']) {
			$this->load->model('tool/image');

			$images = $setting['image'];

			$sort_order = array();

			foreach ($images as $key => $value) {
				$sort_order[$key] = $value['sort_order'];
			}

			array_multisort($sort_order, SORT_ASC, $images);

			foreach ($images as $image) {
				$image_info = array();

				if (isset($image['link'])) {
					$image_info['link'] = trim($image['link']);
				} else {
					$image_info['link'] = '';
				}

				if (isset($image['image']) && is_file(DIR_IMAGE . $image['image'])) {
					$image_info['image'] = $this->model_tool_image->resize($image['image'], $setting['width'], $setting['height']);
				} else {
					$image_info['image'] = $this->model_tool_image->resize('placeholder.png', $setting['width'], $setting['height']);
				}

				$data['images'][] = $image_info;
			}
		}

		if ($data['images']) {
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/image_row.tpl')) {
				return $this->load->view($this->config->get('config_template') . '/template/module/image_row.tpl', $data);
			} else {
				return $this->load->view('default/template/module/image_row.tpl', $data);
			}
		}
	}
}